
import java.io.IOException;

public class ReceiveThread extends Thread {

    private byte[] message = null;
    private Mailbox mailbox;

    public ReceiveThread(Mailbox mbox) {
        this.mailbox = mbox;
    }

    public void run() {
        while (true) {
            try {
                message = mailbox.getMessage();
                try {
                    sleep(10);
                } catch (InterruptedException ex) {
                }
            } catch (IOException ex) {
            }
        }
    }

    public byte[] getMessage() {
        byte[] msg = message;
        message = null;
        return msg;
    }

    public boolean hasMessage() {
        return (message != null);
    }
}